package com.example.mymvvmdemo.models.message_detail;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import androidx.lifecycle.ViewModelProvider;

import com.example.mymvvmdemo.R;
import com.example.mymvvmdemo.base.BaseLoadActivity;
import com.example.mymvvmdemo.databinding.ActivityMessageDetailBinding;
import com.example.mymvvmdemo.dialog.LoadingAnimDialog;

public class MessageDetailActivity extends BaseLoadActivity<ActivityMessageDetailBinding> implements View.OnClickListener {

    public static void startMessageDetailActivity(Activity activity, int id) {
        Intent intent = new Intent(activity, MessageDetailActivity.class);
        intent.putExtra("id", id);
        activity.startActivity(intent);
    }

    private MessageDetailViewModel viewModel;
    /*** 加载时候的Dialog */
    private LoadingAnimDialog loadingDialog;

    @Override
    protected void showDialog() {
        if (loadingDialog == null)
            loadingDialog = new LoadingAnimDialog(this, getResources().getString(R.string.load));
        if (!loadingDialog.isShowing()) loadingDialog.show(this);
    }

    @Override
    protected void dismissDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.close(this);
        }
    }

    @Override
    protected void initData() {
        viewModel = new ViewModelProvider(this).get(MessageDetailViewModel.class);
        initTitle(getString(R.string.message_detail_title));
    }

    @Override
    protected void initListener() {
        binding.include.ivBack.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }

    }

    /*********************************自定义方法*************************************/
    public void initTitle(String title) {
        binding.include.tvTitle.setVisibility(View.VISIBLE);
        binding.include.tvTitle.setText(title);
    }


}